﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Timetable.Site.Models;
using Time = Timetable.Site.Host.Time.Time;

namespace Timetable.Site.Controllers.Api
{
    public class TimeController : BaseApiController<Time>
    {
        /// <summary>
        /// ???
        /// </summary>
        /// <returns></returns>
        public HttpResponseMessage GetAll()
        {
            return CreateResponse<IEnumerable<TimeModel>>(privateGetAll);
        }

       
        private IEnumerable<TimeModel> privateGetAll()
        {
            var result = new List<TimeModel>();
            var times = TimeService.GetAll();

            foreach (var time in times)
            {
                result.Add(new TimeModel { Id = time.Id, StartTime = time.Start.ToString(@"hh\:mm"), EndTime = time.End.ToString(@"hh\:mm") });
            }

            return result;
        }
    }
}